package com.bytedance.scenedemo.group.drawer;

import com.bytedance.scene.Scene;
import com.bytedance.scene.ui.template.NavigationViewScene;
import com.bytedance.scenedemo.utility.ColorUtil;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.IntentParams;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.agp.utils.Color;
import ohos.agp.utils.TextAlignment;

import java.util.LinkedHashMap;

/**
 * Created by JiangQi on 8/3/18.
 */
public class NavigationViewSample extends NavigationViewScene {

    @Override
    protected LayoutScatter onGetLayoutInflater() {
        setType(1);
        return super.onGetLayoutInflater();

    }

    @Override
    protected LinkedHashMap<String, Scene> getSceneMap() {

        LinkedHashMap<String,Scene> map=new LinkedHashMap<>();
        map.put("0", getScene(0));
        map.put("1", getScene(1));
        map.put("2", getScene(2));
        map.put("3", getScene(3));
        return map;
    }

    private Scene getScene(int index) {
        Scene scene = new DrawerChildScene();
        IntentParams intentParams = new IntentParams();
        intentParams.setParam("index",index);
        scene.setArguments(intentParams);
        return scene;
    }

    /**
     * ChildScene
     *
     * @author
     * @since 2021-06-02
     */
    class DrawerChildScene extends Scene{
        @Override
        public Component onCreateView(LayoutScatter scatter, ComponentContainer container, Intent intent) {
            Text text = new Text(requireSceneContext());
            ComponentContainer.LayoutConfig config = new ComponentContainer.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT,ComponentContainer.LayoutConfig.MATCH_PARENT);
            text.setLayoutConfig(config);
            IntentParams intentParams = getArguments();
            int index = (int) intentParams.getParam("index");
            text.setBackground(ColorUtil.getMaterialColor(index));
            text.setTextColor(Color.BLACK);
            text.setTextSize(16, Text.TextSizeType.FP);
            text.setTextAlignment(TextAlignment.CENTER);
            text.setText("Child Scene #"+index);
            return text;
        }
    }
}
